package com.sword.service.impl.stock.product;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sword.constant.MessageConstant;
import com.sword.page.PageResult;
import com.sword.page.QueryPageBean;
import com.sword.pojo.stock.product.Productlist;
import com.sword.service.impl.BaseServiceImpl;
import com.sword.service.impl.BasicBaseServiceImpl;
import com.sword.service.stock.product.ProductListService;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class ProductListServiceImpl extends BasicBaseServiceImpl<Productlist> implements ProductListService {
	
	/**
	 * 分页查询商品总分类
	 *
	 * @param queryPageBean 分页查询
	 * @return com.sword.page.PageResult
	 * @author <1254087415@qq.com>
	 * @since 2021/6/5 11:49
	 */
	@Override
	public PageResult queryProductUnit(QueryPageBean queryPageBean) {
		QueryWrapper<Productlist> wrapper = new QueryWrapper<>();
		
		String queryString = queryPageBean.getQueryString();
		
		if (queryString != null) {
			wrapper.like("productlistid", queryString).or().like("Remark", queryString);
		}
		
		IPage<Productlist> iPage = super.queryPageList(wrapper, queryPageBean.getPage(), queryPageBean.getLimit());
		
		return new PageResult(0, MessageConstant.QUERY_PRODOCTLIST_SUCCESS, iPage.getTotal(), iPage.getRecords());
	}
	
	/**
	 * 添加商品细分类
	 *
	 * @param productlist 商品细分类数据
	 * @return java.lang.Integer
	 * @author <1254087415@qq.com>
	 * @since 2021/6/5 11:50
	 */
	@Override
	public Integer addProductList(Productlist productlist) {
		productlist.setCreateDate(new Date());
		return super.save(productlist);
	}
	
	/**
	 * 编辑商品细分类
	 *
	 * @param productlist 商品细分类数据
	 * @return java.lang.Integer
	 * @author <1254087415@qq.com>
	 * @since 2021/6/5 13:27
	 */
	@Override
	public Integer editProductList(Productlist productlist) {
		return super.update(productlist);
	}
	
	/**
	 * 删除商品细分类
	 *
	 * @param id 商品细分类id
	 * @return java.lang.Integer
	 * @author <1254087415@qq.com>
	 * @since 2021/6/5 13:33
	 */
	@Override
	public Integer deleteProductList(Integer id) {
		return deleteById(Long.valueOf(id));
	}
	
	
}
